﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MinoSoft.sslpDataSetTableAdapters;

namespace MinoSoft
{
    public partial class FrmMain : Form
    {
        public FrmMain()
        {
            InitializeComponent();
            Change_BackgroundImage(LocalProperties.getInstance().getProperty("wallpapper"), LocalProperties.getInstance().getProperty("wpLayout"));
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            FrmVentas frmVenta = new FrmVentas();
            frmVenta.MdiParent = this;
            frmVenta.Show();
        }

        private void toolStrip2_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            FrmArticulos frmArticulo = new FrmArticulos();
            frmArticulo.MdiParent = this;
            frmArticulo.Show();
        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            FrmProveedores frmProveedor = new FrmProveedores();
            frmProveedor.MdiParent = this;
            frmProveedor.Show();
        }

        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            FrmBalances frmBalance = new FrmBalances();
            frmBalance.MdiParent = this;
            frmBalance.Show();
        }

        private void toolStripButton5_Click(object sender, EventArgs e)
        {
            FrmGastos frmGasto = new FrmGastos();
            frmGasto.MdiParent = this;
            frmGasto.Show();
        }

        private void PropiedadestoolStripMenuItem1_Click(object sender, EventArgs e)
        {
            FrmPropiedades frmPropiedad = new FrmPropiedades();
            //frmPropiedad.MdiParent = this;
            frmPropiedad.ShowDialog();
            Change_BackgroundImage(LocalProperties.getInstance().getProperty("wallpapper"), LocalProperties.getInstance().getProperty("wpLayout"));
        }

        private void btnGuardar_Click(object sender, EventArgs e)
        {
            FrmCajaInicial frmCajaInicial = new FrmCajaInicial();
            frmCajaInicial.ShowDialog();

            refrescarCajaInicial();

        }

        private void refrescarCajaInicial()
        {
            CAJAINICIALTableAdapter cajaInicial = new CAJAINICIALTableAdapter();
            sslpDataSet.CAJAINICIALDataTable table = cajaInicial.GetDataByFecha(DateTime.Now.Date);

            lblCajaInicial.Text = table.Rows[0]["IMPORTE"].ToString();
        }

        private void modificarCajaInicialToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmPassword frmPass = new FrmPassword();
            frmPass.ShowDialog();
        }

        private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            /*DialogResult res = Dialogos.YesNo("¿Esta seguro que desea salir de la aplicación?",Application.ProductName);

            if (DialogResult.No.Equals(res))
                e.Cancel = true;            */
        }

        private void cerrarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Change_BackgroundImage(string _path, string layout)
        {
            string imagepath = _path;
            System.IO.FileStream fs;
            // MDI Form image background layout change here
            //(Remember control imagebakground layout take default form background layount )
            if ("Centrado".Equals(layout))
                this.BackgroundImageLayout = ImageLayout.Center;
            if ("Mosaico".Equals(layout))
                this.BackgroundImageLayout = ImageLayout.Tile;
            if ("Expandido".Equals(layout))
                this.BackgroundImageLayout = ImageLayout.Stretch;

            // Checking File exists if yes go --->
            if (System.IO.File.Exists(imagepath))
            {
                // Read Image file
                fs = System.IO.File.OpenRead(imagepath);
                fs.Position = 0;
                // Change MDI From back ground picture
                foreach (Control ctl in this.Controls)
                {
                    if (ctl is MdiClient)
                    {
                        //ctl.BackColor = Color.AntiqueWhite;
                        ctl.BackgroundImage = System.Drawing.Image.FromStream(fs);
                        break;
                    }
                }
            }
            else
            {
                // Change MDI From back ground picture
                foreach (Control ctl in this.Controls)
                {
                    if (ctl is MdiClient)
                    {
                        //ctl.BackColor = Color.AntiqueWhite;
                        ctl.BackgroundImage = null;
                        break;
                    }
                }
            }
        }
    }
}
